import { Engine } from '@designable/core'
import {
  IFormilySchema,
  transformToSchema,
  transformToTreeNode,
} from '@designable/formily-transformer'
import { message } from 'antd'

export const saveSchema = (designer: Engine) => {
  const value = transformToSchema(designer.getCurrentTree())
  // localStorage.setItem(
  //   'formily-schema',
  //   JSON.stringify(value)
  // )
  message.success('Save Success')
  return value
}

export const loadInitialSchema = (designer: Engine,schema:IFormilySchema = {}) => {
  try {
    if(schema) return designer.setCurrentTree(transformToTreeNode(schema))
    
    // designer.setCurrentTree(
    //   transformToTreeNode(JSON.parse(localStorage.getItem('formily-schema')!))
    // )
  } catch {}
}
